package com.jinlingxiu.app.mvp.ui.activity

import android.content.Intent
import android.os.Bundle
import com.jaeger.library.StatusBarUtil
import com.jinlingxiu.app.R
import com.jinlingxiu.app.mvp.contract.LoginContract
import com.jinlingxiu.app.mvp.presenter.LoginPresenter
import com.xdja.easymvp.base.BaseActivity
import kotlinx.android.synthetic.main.activity_login.*
import org.koin.androidx.scope.lifecycleScope

/**
 * 描述: 登录页
 * Create by yuanwanli
 * Date 2020/09/09
 */
class LoginActivity : BaseActivity<LoginPresenter>(), LoginContract.View {
    override var mPresenter: LoginPresenter? = lifecycleScope.get()

    override fun initView(savedInstanceState: Bundle?): Int = R.layout.activity_login

    override fun initData(savedInstanceState: Bundle?) {
        StatusBarUtil.setTransparent(this)
        StatusBarUtil.setLightMode(this)
        btnStart.setOnClickListener {
            val name = etName.text.toString()
            val unitName = etUnitName.text.toString()
            if (name.isEmpty()) {
                showMessage("请先输入姓名")
                return@setOnClickListener
            }
            if (unitName.isEmpty()) {
                showMessage("请先输入机构名称")
                return@setOnClickListener
            }
            mPresenter?.login(name, unitName)
        }
    }

    override fun loginSuccess() {
        startActivity(Intent(this, MainActivity::class.java))
        finish()
    }
}
